﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FoundationClass.Data;

namespace FoundationClass.Entity
{
    public class ServiceRecord
    {
        public int Id { get; set; }
        public DateTime RecordStart { get; set; }
        public DateTime? RecordEnd { get; set; }
        public int RecordStatus { get; set; }
        public string RecordAmount { get; set; }
        public Computer Computer { get; set; }
        public Payment Payment { get; set; }
        public Promotion Promotion { get; set; }

        public void ChangeCompuer(int computerId)
        {
            ServiceRecordData.ChangeComputer(Id, computerId);
            Computer = ComputerData.GetComputer(computerId);
        }

        public double CalculateTotalAmount()
        {
            

            if (RecordEnd != null)
            {
                TimeSpan ts = RecordEnd.Value.Subtract(RecordStart);
                RecordAmount = (new TimeSpan(ts.Hours, ts.Minutes, ts.Seconds)).ToString();
                if (Promotion.IsTotal)
                    return Promotion.PriceRate;
                //return (ts.Hours * Promotion.PriceRate) + (ts.Minutes <= 30 ? (Promotion.PriceRate / 2) : 0) + (ts.Minutes > 30 ? Promotion.PriceRate : 0);
                return (ts.Hours * Promotion.PriceRate) + (ts.Minutes <= 5 ? 0 : ((ts.Minutes <= 30 ? (Promotion.PriceRate / 2) : 0) + (ts.Minutes > 30 ? Promotion.PriceRate : 0)));
            }

            
            return 0;
        }
    }
}
